<?php

namespace ServerApp\lib\server\http;

use ServerApp\lib\config\LogConfig;
use ServerApp\lib\memory\Chan;
use ServerApp\lib\process\SProcess;
use ServerApp\lib\util\ServerHelper;

class createHttp
{
    private static $instance = null;

    private function __construct($namespace, $is_debug, IHttp $func2)
    {
        ServerHelper::init();
        LogConfig::init();
        Chan::getInstance();
        (new SProcess(function() use ($func2){
            HttpPush::init($func2);
        }))->start();
        (new SProcess(function() use ($namespace, $is_debug, $func2){
            (new Http($namespace, $is_debug, $func2))->run();
        }))->start();
    }

    public static function getInstance($namespace, $is_debug, IHttp $func2)
    {
        if (self::$instance === null) {
            self::$instance = new self($namespace, $is_debug, $func2);
        }
        return self::$instance;
    }
}